package com.lft.examsys.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lft.examsys.model.IModel;

/**
 * @author ：Qingchen
 * @date ：Created in 2022/3/30 16:19
 * @description：分页查询
 * @modified By：
 * @version: $
 */
public class PageUtil {
    public static <T>  Page<T> getAllByPage(IModel model,Integer page, Integer size, BaseMapper<T> mapper, String elName) {
        page = page == null ? 1 : page;
        size = size == null ? 10 : size;
        QueryWrapper<T> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id");
        Page<T> res = new Page<>(page, size);
        mapper.selectPage(res, wrapper);
        if (elName!="") {
            model.add(elName, res.getRecords());
        }
        model.add("page", res.getCurrent());
        model.add("size", res.getSize());
        model.add("total", res.getPages());
        model.add("count", res.getTotal());
        return res;
    }
}
